#include "ElementCalculatorFactory.h"

using SG::DataStructure::FEM::ElementTypes;
using namespace SG::FEMSolver::Element;

ElementCalculatorFactory::ElementTypeMap ElementCalculatorFactory::s_elements;

void ElementCalculatorFactory::Register (ElementTypes type, ElementCalculatorFactory::ElementCreateFuncPtr cb)
{
    s_elements[type] = cb;
}

void ElementCalculatorFactory::UnRegister (ElementTypes type)
{
    s_elements.erase (type);
}

ElementCalculatorSP ElementCalculatorFactory::Create (ElementTypes type)
{
    auto it = s_elements.find (type);
    if (it != s_elements.end ())
    {
        return (it->second) ();
    }

    return nullptr;
}